package com.wpzf.ndhc.controller;

import com.wpzf.common.core.web.domain.AjaxResult;
import com.wpzf.ndhc.service.WpzfNdhcShemeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/scheme")
public class WpzfNdhcShemeController
{
    @Autowired
    WpzfNdhcShemeService  wpzfNdhcShemeService;

    @RequestMapping(value = "/getNdhcyear", method = RequestMethod.POST)
    public AjaxResult getNdhcyear()
    {
        List<Map<String, Object>> rest = wpzfNdhcShemeService.getNdhcyear();
        if (rest != null) {
            return AjaxResult.success("获取年份成功", rest);
        }
        return AjaxResult.error("获取年份 失败", -1);
    }

    @RequestMapping(value = "/getSchemeInfo", method = RequestMethod.POST)
    public AjaxResult getSchemeInfo(@RequestBody Map<String, Object> parm)
    {
        List<Map<String, Object>> rest = wpzfNdhcShemeService.getSchemeInfo(parm);
        if (rest != null) {
            return AjaxResult.success("获取年份成功", rest);
        }
        return AjaxResult.error("获取年份 失败", -1);
    }

    @RequestMapping(value = "/getSchemeInfobypch", method = RequestMethod.POST)
    public AjaxResult getSchemeInfobypch(@RequestBody Map<String, Object> parm)
    {
        Map<String, Object> rest = wpzfNdhcShemeService.getSchemeInfobypch(parm);
        if (rest != null) {
            return AjaxResult.success("获取年份成功", rest);
        }
        return AjaxResult.error("获取年份 失败", -1);
    }

    @RequestMapping(value = "/saveScheme", method = RequestMethod.POST)
    public AjaxResult saveScheme(@RequestBody Map<String, Object> parm)
    {
        int  rest = wpzfNdhcShemeService.saveScheme(parm);
        if (rest>0) {
            return AjaxResult.success("规则保存成功", rest);
        }
        return AjaxResult.error("规则保存失败", -1);
    }
    @RequestMapping(value = "/extract", method = RequestMethod.POST)
    public AjaxResult extract(@RequestBody Map<String, Object> parm)
    {
        int  rest = wpzfNdhcShemeService.extract(parm);
        if (rest>=0)
        {
            return AjaxResult.success("抽取成功", rest);
        }
        if (rest==-1) {
            return AjaxResult.success("该批次已经抽取完成无法再次抽取", rest);
        }
        return AjaxResult.error("抽取成功", -1);
    }
}
